/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package classcreator;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;

/**
 *
 * @author Stefano
 */
public class TransitionInfo {
    private static double outputFormatVersion=1.0;
    
    public int start;
    public int end;
    public String guard="";
    
    public TransitionInfo(int s, int e){
        start=s;
        end=e;
    }
    
    public TransitionInfo(int s, int e, String g){
        start=s;
        end=e;
        setGuard(g);
    }
    
    public void setGuard(String g){
        guard=g;
        guard.replace('\n', ' ');
    }
    
    public boolean isGuarded(){
        return !guard.isEmpty();
    }
    
    public boolean equals(TransitionInfo ti){
        return start==ti.start && end==ti.end && guard.equals(ti.guard);
    }
    
    public static TransitionInfo parse(BufferedReader br, TypeRepository tr) throws IOException{
                br.readLine();
                double version=Double.parseDouble(br.readLine());
                
                if(version<=1.0){
                    int s=Integer.parseInt(br.readLine());
                    int e=Integer.parseInt(br.readLine());
                    String g=br.readLine();
                    return new TransitionInfo(s,e,g);
                }
                //Actual version
                int s=Integer.parseInt(br.readLine());
                int e=Integer.parseInt(br.readLine());
                String g=br.readLine();
                return new TransitionInfo(s,e,g);
    }
    
    public void permanentize(BufferedWriter br, TypeRepository tr) throws IOException{
        br.write("/***/ TransitionInfo: "+String.valueOf(start)+" -> "+String.valueOf(end)+" ["+guard+"]"); br.newLine();
        br.write(String.valueOf(outputFormatVersion)); br.newLine();
                br.write(String.valueOf(start)); br.newLine();
                br.write(String.valueOf(end)); br.newLine();
                br.write(guard); br.newLine();
    }
}
